
#version 460
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout (location = 0) in vec4 InColor;
layout (location = 1) in vec2 InCenter;
layout (location = 2) in float InRadius;
layout (location = 3) in float InWidth;

layout (location = 0) out vec4 OutColor;

//单位是像素
#define BlurWidth   0.4   
#define HalfBlurWidth 0.2 

void main() {

    //计算当前片元到圆心的距离
    float Distance = length(gl_FragCoord.xy - InCenter);
    float InnerRadius = InRadius-InWidth;
    //如果当前片元到圆心的距离小于半径，则该片元在圆内
    if(InRadius >=  Distance+HalfBlurWidth
        && InnerRadius <=  Distance-HalfBlurWidth
    )
    {
        OutColor = InColor;
    }
    else if(
        InRadius >=  Distance-HalfBlurWidth
        &&  InRadius <=Distance+HalfBlurWidth
        )
    {
        //在外环上边缘渐变
        float Alpha=(InRadius-(Distance-HalfBlurWidth))/BlurWidth;
        OutColor = vec4(InColor.rgb,InColor.a*Alpha);
    }
    else if(
        InnerRadius >=  Distance-HalfBlurWidth
        && InnerRadius <= Distance+HalfBlurWidth
    )
    {
        //在内环上边缘渐变
        float Alpha=1-(InnerRadius- (Distance-HalfBlurWidth))/BlurWidth;
        OutColor = vec4(InColor.rgb,InColor.a*Alpha);
    }
    

    else
    {
        discard;
    }

}

